scale_y_continuous(breaks = seq(0, 600, by = 50)) +
labs(title = paste("Trajectory of: t3 in trial 17"), x = "x position along tank width", y = "y position")+
geom_point(aes(x=avg.redlight.y, y=avg.redlight.x), colour="red") +
geom_rect(mapping = aes(xmin = avg.redlight.y - 10, xmax = avg.redlight.y + 10, ymin = avg.redlight.x - 10, ymax = avg.redlight.x + 10), color = 'red', alpha = 0)+
geom_point(aes(x=avg.fooddrop.y, y=avg.fooddrop.x), colour="brown") +
geom_rect(mapping = aes(xmin = avg.fooddrop.y - 10, xmax = avg.fooddrop.y + 10, ymin = avg.fooddrop.x - 10, ymax = avg.fooddrop.x + 10), color = 'brown', alpha = 0)+
geom_text(aes(x=avg.redlight.y, label="\nred light", y=avg.redlight.x + 30), colour="red", text=element_text(size=11))
w
setwd('/Users/emmacosta/Dropbox/KillifishFeederPaper_AndrewMcKay/Revision/Figures_revised/Ai_files/Emma_draft/')
pdf("220811_t3_trial17_trajectory.pdf")
w
dev.off()
#Plot xy trajectory of a single fish
w <- ggplot(df.subset, aes(x = y2, y = x2))+
geom_path(aes(colour=seconds), lineend = "round")+
scale_color_gradientn( colours = c("skyblue", "blue", "red", "orange", "yellow"))+
scale_x_continuous(breaks = seq(0, 600, by = 50))+
scale_y_continuous(breaks = seq(0, 700, by = 50)) +
labs(title = paste("Trajectory of: t3 in trial 17"), x = "x position along tank width", y = "y position")+
geom_point(aes(x=avg.redlight.y, y=avg.redlight.x), colour="red") +
geom_rect(mapping = aes(xmin = avg.redlight.y - 10, xmax = avg.redlight.y + 10, ymin = avg.redlight.x - 10, ymax = avg.redlight.x + 10), color = 'red', alpha = 0)+
geom_point(aes(x=avg.fooddrop.y, y=avg.fooddrop.x), colour="brown") +
geom_rect(mapping = aes(xmin = avg.fooddrop.y - 10, xmax = avg.fooddrop.y + 10, ymin = avg.fooddrop.x - 10, ymax = avg.fooddrop.x + 10), color = 'brown', alpha = 0)+
geom_text(aes(x=avg.redlight.y, label="\nred light", y=avg.redlight.x + 30), colour="red", text=element_text(size=11))
w
#Plot xy trajectory of a single fish
w <- ggplot(df.subset, aes(x = y2, y = x2))+
geom_path(aes(colour=seconds), lineend = "round")+
scale_color_gradientn( colours = c("skyblue", "blue", "red", "orange", "yellow"))+
scale_x_continuous(breaks = seq(0, 600, by = 50))+
scale_y_continuous(breaks = seq(0, 700, by = 50)) +
labs(title = paste("Trajectory of: t3 in trial 17"), x = "x position along tank width", y = "y position")+
geom_point(aes(x=avg.redlight.y, y=avg.redlight.x), colour="red") +
geom_rect(mapping = aes(xmin = avg.redlight.y - 10, xmax = avg.redlight.y + 10, ymin = avg.redlight.x - 10, ymax = avg.redlight.x + 10), color = 'red', alpha = 0)+
geom_point(aes(x=avg.fooddrop.y, y=avg.fooddrop.x), colour="brown") +
geom_rect(mapping = aes(xmin = avg.fooddrop.y - 10, xmax = avg.fooddrop.y + 10, ymin = avg.fooddrop.x - 10, ymax = avg.fooddrop.x + 10), color = 'brown', alpha = 0)+
geom_text(aes(x=avg.redlight.y, label="\nred light", y=avg.redlight.x + 30), colour="red", text=element_text(size=11))
w
setwd('/Users/emmacosta/Dropbox/KillifishFeederPaper_AndrewMcKay/Revision/Figures_revised/Ai_files/Emma_draft/')
pdf("220811_t3_trial17_trajectory.pdf")
w
dev.off()
#Source: https://cran.r-project.org/web/packages/MKpower/vignettes/MKpower.html#wilcoxon-rank-sum-and-signed-rank-tests
library(MKpower)
install.packages('MKpower')
#Source: https://cran.r-project.org/web/packages/MKpower/vignettes/MKpower.html#wilcoxon-rank-sum-and-signed-rank-tests
library(MKpower)
install.packages("gmp", type="source", configure.args = "--with-gmp-include=/usr/local/Cellar/gmp/6.2.1_1/include/")
install.packages("gmp")
yum install  libgmp3-dev
apt-get install  libgmp3-dev
which('zoo')
library(zoo)
w
g <- ggplot_build(w)
g$data[[1]]
View(g$data[[1]])
View(df.subset)
df.subset <- subset(df, recording_num == 3)
df.subset <- subset(df.subset, seconds <= 18)
#Plot xy trajectory of a single fish
w <- ggplot(df.subset, aes(x = y2, y = x2))+
geom_path(aes(colour=seconds), lineend = "round")+
scale_color_gradientn( colours = c("skyblue", "blue", "red", "orange", "yellow"))+
scale_x_continuous(breaks = seq(0, 600, by = 50))+
scale_y_continuous(breaks = seq(0, 700, by = 50)) +
labs(title = paste("Trajectory of: t3 in trial 3"), x = "x position along tank width", y = "y position")+
geom_point(aes(x=avg.redlight.y, y=avg.redlight.x), colour="red") +
geom_rect(mapping = aes(xmin = avg.redlight.y - 10, xmax = avg.redlight.y + 10, ymin = avg.redlight.x - 10, ymax = avg.redlight.x + 10), color = 'red', alpha = 0)+
geom_point(aes(x=avg.fooddrop.y, y=avg.fooddrop.x), colour="brown") +
geom_rect(mapping = aes(xmin = avg.fooddrop.y - 10, xmax = avg.fooddrop.y + 10, ymin = avg.fooddrop.x - 10, ymax = avg.fooddrop.x + 10), color = 'brown', alpha = 0)+
geom_text(aes(x=avg.redlight.y, label="\nred light", y=avg.redlight.x + 30), colour="red", text=element_text(size=11))
w
View(df.subset)
g <- ggplot_build(w)
ggdf <- g$data[[1]]
View(ggdf)
df.subset <- subset(df, recording_num == 17)
df.subset <- subset(df.subset, seconds <= 18)
#Plot xy trajectory of a single fish
w <- ggplot(df.subset, aes(x = y2, y = x2))+
geom_path(aes(colour=seconds), lineend = "round")+
scale_color_gradientn( colours = c("skyblue", "blue", "red", "orange", "yellow"))+
scale_x_continuous(breaks = seq(0, 600, by = 50))+
scale_y_continuous(breaks = seq(0, 700, by = 50)) +
labs(title = paste("Trajectory of: t3 in trial 17"), x = "x position along tank width", y = "y position")+
geom_point(aes(x=avg.redlight.y, y=avg.redlight.x), colour="red") +
geom_rect(mapping = aes(xmin = avg.redlight.y - 10, xmax = avg.redlight.y + 10, ymin = avg.redlight.x - 10, ymax = avg.redlight.x + 10), color = 'red', alpha = 0)+
geom_point(aes(x=avg.fooddrop.y, y=avg.fooddrop.x), colour="brown") +
geom_rect(mapping = aes(xmin = avg.fooddrop.y - 10, xmax = avg.fooddrop.y + 10, ymin = avg.fooddrop.x - 10, ymax = avg.fooddrop.x + 10), color = 'brown', alpha = 0)+
geom_text(aes(x=avg.redlight.y, label="\nred light", y=avg.redlight.x + 30), colour="red", text=element_text(size=11))
w
g <- ggplot_build(w)
View(ggdf)
df.subset <- subset(df, recording_num == 17)
df.subset <- subset(df.subset, seconds <= 18)
#Plot xy trajectory of a single fish
w <- ggplot(df.subset, aes(x = y2, y = x2))+
geom_path(aes(colour=seconds), lineend = "round")+
scale_color_gradientn( colours = c("skyblue", "blue", "red", "orange", "yellow"))+
scale_x_continuous(breaks = seq(0, 600, by = 50))+
scale_y_continuous(breaks = seq(0, 700, by = 50)) +
labs(title = paste("Trajectory of: t3 in trial 17"), x = "x position along tank width", y = "y position")+
geom_point(aes(x=avg.redlight.y, y=avg.redlight.x), colour="red") +
geom_rect(mapping = aes(xmin = avg.redlight.y - 10, xmax = avg.redlight.y + 10, ymin = avg.redlight.x - 10, ymax = avg.redlight.x + 10), color = 'red', alpha = 0)+
geom_point(aes(x=avg.fooddrop.y, y=avg.fooddrop.x), colour="brown") +
geom_rect(mapping = aes(xmin = avg.fooddrop.y - 10, xmax = avg.fooddrop.y + 10, ymin = avg.fooddrop.x - 10, ymax = avg.fooddrop.x + 10), color = 'brown', alpha = 0)+
geom_text(aes(x=avg.redlight.y, label="\nred light", y=avg.redlight.x + 30), colour="red", text=element_text(size=11))
g <- ggplot_build(w)
#I will define "yellow"= highest velocity range for each plot as any hex codes that begin with E or F
ggdf <- g$data[[1]]
View(ggdf)
library(ggplot2)
library(gridExtra)
library(data.table)
#install.packages("effsize")
library("effsize")
data = read.table("/Users/emmacosta/Dropbox/KillifishFeederPaper_AndrewMcKay/Revision/Protofigures/CohenD_behavior/220716_automatedt1s.csv", sep = ',', header = TRUE)
data
# might need to convert data$Age..days.post.hatching. into factor
r = cohen.d(data$LearningIndex_2, data$AgeCat)
## the wilcoxon is not significant
wilcox.test(data[data$AgeCat == "Young",c("LearningIndex_2")],data[data$AgeCat == "Old",c("LearningIndex_2")])
r
data = read.table("/Users/emmacosta/Dropbox/KillifishFeederPaper_AndrewMcKay/Revision/Protofigures/CohenD_behavior/manualt1s.csv", sep = ',', header = TRUE)
data = read.table("/Users/emmacosta/Dropbox/KillifishFeederPaper_AndrewMcKay/Revision/Others/Protofigures/CohenD_behavior/manualt1s.csv", sep = ',', header = TRUE)
# might need to convert data$Age..days.post.hatching. into factor
r = cohen.d(data$LearningIndex_2, data$AgeCat)
## the wilcoxon is not significant
wilcox.test(data[data$AgeCat == "Young",c("LearningIndex_2")],data[data$AgeCat == "Old",c("LearningIndex_2")])
r
#------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#Just x velocity (which is the vertical component)
#------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
setwd('/Users/emmacosta/Library/CloudStorage/Box-Box/Emma Costa Externally Shareable Files/TWC Lab/03_Collaborations/AndrewMcKay/FeederPaper/2018 Old-Young Training Trajectories/DLC Trained Trajectories/Filtered and Interpolated with Kinematics/Vector Velocities/')
f <- list.files(pattern=c("*.csv"), full.names=F, recursive=FALSE)
#make one large table
tables <- lapply(f, read.csv)
df <- do.call(rbind, tables)
#add one to the trial #'s so it's no longer 0 indexed
df$recording_num <- df$recording_num + 1
View(df)
#compute rolling averages
df <- df %>%
dplyr::arrange(fishnum) %>%
dplyr::group_by(fishnum,recording_num) %>%
dplyr::mutate(velocity_x_5frame = zoo::rollmean(velocity_x, k = 5, fill = NA),  #5 frames
velocity_x_10frame = zoo::rollmean(velocity_x, k = 10, fill = NA), #10 frames
velocity_x_20frame = zoo::rollmean(velocity_x, k = 20, fill = NA), #20 frames
velocity_x_40frame = zoo::rollmean(velocity_x, k = 40, fill = NA) #40 frames
)
df <- subset(df, seconds <= 18)
df <- subset(df, recording_num <= 17)
View(df)
subset(df, fishnum <= '3')$velocity_x_20frame
mean(subset(df, fishnum <= '3')$velocity_x_20frame)
mean(subset(df, fishnum <= '3')$velocity_x_20frame, na.rm = T)
mean(subset(df, fishnum <= '5')$velocity_x_20frame, na.rm = T)
mean(subset(df, fishnum <= '13')$velocity_x_20frame, na.rm = T)
mean(subset(df, fishnum <= '14')$velocity_x_20frame, na.rm = T)
mean(subset(df, fishnum <= '15')$velocity_x_20frame, na.rm = T)
df.subset <- subset(df, fishnum <= '3')
upper <- quantile(df.subset$velocity_x_20frame, 0.85, na.rm = T)[[1]]
lower <- quantile(df.subset$velocity_x_20frame, 0.15, na.rm = T)[[1]]
data <- df %>%
mutate(velocity_x2 = case_when(
velocity_x_20frame >= upper ~ upper,
T ~ velocity_x_20frame
)) %>%
mutate(velocity_x3 = case_when(
velocity_x2 <= lower ~ lower,
T ~ velocity_x2
))
View(data)
mean(data$velocity_x3, na.rm = T)
df.subset <- subset(df, fishnum <= '5')
upper <- quantile(df.subset$velocity_x_20frame, 0.85, na.rm = T)[[1]]
lower <- quantile(df.subset$velocity_x_20frame, 0.15, na.rm = T)[[1]]
data <- df %>%
mutate(velocity_x2 = case_when(
velocity_x_20frame >= upper ~ upper,
T ~ velocity_x_20frame
)) %>%
mutate(velocity_x3 = case_when(
velocity_x2 <= lower ~ lower,
T ~ velocity_x2
))
mean(data$velocity_x3, na.rm = T)
df.subset <- subset(df, fishnum <= '13')
upper <- quantile(df.subset$velocity_x_20frame, 0.85, na.rm = T)[[1]]
lower <- quantile(df.subset$velocity_x_20frame, 0.15, na.rm = T)[[1]]
data <- df %>%
mutate(velocity_x2 = case_when(
velocity_x_20frame >= upper ~ upper,
T ~ velocity_x_20frame
)) %>%
mutate(velocity_x3 = case_when(
velocity_x2 <= lower ~ lower,
T ~ velocity_x2
))
mean(data$velocity_x3, na.rm = T)
df.subset <- subset(df, fishnum <= '14')
upper <- quantile(df.subset$velocity_x_20frame, 0.85, na.rm = T)[[1]]
lower <- quantile(df.subset$velocity_x_20frame, 0.15, na.rm = T)[[1]]
data <- df %>%
mutate(velocity_x2 = case_when(
velocity_x_20frame >= upper ~ upper,
T ~ velocity_x_20frame
)) %>%
mutate(velocity_x3 = case_when(
velocity_x2 <= lower ~ lower,
T ~ velocity_x2
))
mean(data$velocity_x3, na.rm = T)
df.subset <- subset(df, fishnum <= '15')
upper <- quantile(df.subset$velocity_x_20frame, 0.85, na.rm = T)[[1]]
lower <- quantile(df.subset$velocity_x_20frame, 0.15, na.rm = T)[[1]]
data <- df %>%
mutate(velocity_x2 = case_when(
velocity_x_20frame >= upper ~ upper,
T ~ velocity_x_20frame
)) %>%
mutate(velocity_x3 = case_when(
velocity_x2 <= lower ~ lower,
T ~ velocity_x2
))
mean(data$velocity_x3, na.rm = T)
df.subset <- subset(df, fishnum <= '16')
upper <- quantile(df.subset$velocity_x_20frame, 0.85, na.rm = T)[[1]]
lower <- quantile(df.subset$velocity_x_20frame, 0.15, na.rm = T)[[1]]
data <- df %>%
mutate(velocity_x2 = case_when(
velocity_x_20frame >= upper ~ upper,
T ~ velocity_x_20frame
)) %>%
mutate(velocity_x3 = case_when(
velocity_x2 <= lower ~ lower,
T ~ velocity_x2
))
mean(data$velocity_x3, na.rm = T)
df.subset <- subset(df, fishnum <= '26')
upper <- quantile(df.subset$velocity_x_20frame, 0.85, na.rm = T)[[1]]
lower <- quantile(df.subset$velocity_x_20frame, 0.15, na.rm = T)[[1]]
data <- df %>%
mutate(velocity_x2 = case_when(
velocity_x_20frame >= upper ~ upper,
T ~ velocity_x_20frame
)) %>%
mutate(velocity_x3 = case_when(
velocity_x2 <= lower ~ lower,
T ~ velocity_x2
))
mean(data$velocity_x3, na.rm = T)
df.subset <- subset(df, fishnum <= '2')
upper <- quantile(df.subset$velocity_x_20frame, 0.85, na.rm = T)[[1]]
lower <- quantile(df.subset$velocity_x_20frame, 0.15, na.rm = T)[[1]]
data <- df %>%
mutate(velocity_x2 = case_when(
velocity_x_20frame >= upper ~ upper,
T ~ velocity_x_20frame
)) %>%
mutate(velocity_x3 = case_when(
velocity_x2 <= lower ~ lower,
T ~ velocity_x2
))
mean(data$velocity_x3, na.rm = T)
df.subset <- subset(df, fishnum <= '4')
upper <- quantile(df.subset$velocity_x_20frame, 0.85, na.rm = T)[[1]]
lower <- quantile(df.subset$velocity_x_20frame, 0.15, na.rm = T)[[1]]
data <- df %>%
mutate(velocity_x2 = case_when(
velocity_x_20frame >= upper ~ upper,
T ~ velocity_x_20frame
)) %>%
mutate(velocity_x3 = case_when(
velocity_x2 <= lower ~ lower,
T ~ velocity_x2
))
mean(data$velocity_x3, na.rm = T)
df.subset <- subset(df, fishnum <= '1')
upper <- quantile(df.subset$velocity_x_20frame, 0.85, na.rm = T)[[1]]
lower <- quantile(df.subset$velocity_x_20frame, 0.15, na.rm = T)[[1]]
data <- df %>%
mutate(velocity_x2 = case_when(
velocity_x_20frame >= upper ~ upper,
T ~ velocity_x_20frame
)) %>%
mutate(velocity_x3 = case_when(
velocity_x2 <= lower ~ lower,
T ~ velocity_x2
))
mean(data$velocity_x3, na.rm = T)
df.subset <- subset(df, fishnum <= '9')
upper <- quantile(df.subset$velocity_x_20frame, 0.85, na.rm = T)[[1]]
lower <- quantile(df.subset$velocity_x_20frame, 0.15, na.rm = T)[[1]]
data <- df %>%
mutate(velocity_x2 = case_when(
velocity_x_20frame >= upper ~ upper,
T ~ velocity_x_20frame
)) %>%
mutate(velocity_x3 = case_when(
velocity_x2 <= lower ~ lower,
T ~ velocity_x2
))
mean(data$velocity_x3, na.rm = T)
df.subset <- subset(df, fishnum <= '19')
upper <- quantile(df.subset$velocity_x_20frame, 0.85, na.rm = T)[[1]]
lower <- quantile(df.subset$velocity_x_20frame, 0.15, na.rm = T)[[1]]
data <- df %>%
mutate(velocity_x2 = case_when(
velocity_x_20frame >= upper ~ upper,
T ~ velocity_x_20frame
)) %>%
mutate(velocity_x3 = case_when(
velocity_x2 <= lower ~ lower,
T ~ velocity_x2
))
mean(data$velocity_x3, na.rm = T)
df.subset <- subset(df, fishnum <= '20')
upper <- quantile(df.subset$velocity_x_20frame, 0.85, na.rm = T)[[1]]
lower <- quantile(df.subset$velocity_x_20frame, 0.15, na.rm = T)[[1]]
data <- df %>%
mutate(velocity_x2 = case_when(
velocity_x_20frame >= upper ~ upper,
T ~ velocity_x_20frame
)) %>%
mutate(velocity_x3 = case_when(
velocity_x2 <= lower ~ lower,
T ~ velocity_x2
))
mean(data$velocity_x3, na.rm = T)
####
df.subset <- subset(df, fishnum <= '3')
upper <- quantile(df.subset$velocity_x, 0.85, na.rm = T)[[1]]
lower <- quantile(df.subset$velocity_x, 0.15, na.rm = T)[[1]]
data <- df %>%
mutate(velocity_x2 = case_when(
velocity_x >= upper ~ upper,
T ~ velocity_x
)) %>%
mutate(velocity_x3 = case_when(
velocity_x2 <= lower ~ lower,
T ~ velocity_x2
))
mean(data$velocity_x3, na.rm = T)
####
df.subset <- subset(df, fishnum <= '5')
upper <- quantile(df.subset$velocity_x, 0.85, na.rm = T)[[1]]
lower <- quantile(df.subset$velocity_x, 0.15, na.rm = T)[[1]]
data <- df %>%
mutate(velocity_x2 = case_when(
velocity_x >= upper ~ upper,
T ~ velocity_x
)) %>%
mutate(velocity_x3 = case_when(
velocity_x2 <= lower ~ lower,
T ~ velocity_x2
))
mean(data$velocity_x3, na.rm = T)
####
df.subset <- subset(df, fishnum <= '13')
upper <- quantile(df.subset$velocity_x, 0.85, na.rm = T)[[1]]
lower <- quantile(df.subset$velocity_x, 0.15, na.rm = T)[[1]]
data <- df %>%
mutate(velocity_x2 = case_when(
velocity_x >= upper ~ upper,
T ~ velocity_x
)) %>%
mutate(velocity_x3 = case_when(
velocity_x2 <= lower ~ lower,
T ~ velocity_x2
))
mean(data$velocity_x3, na.rm = T)
####
df.subset <- subset(df, fishnum <= '14')
upper <- quantile(df.subset$velocity_x, 0.85, na.rm = T)[[1]]
lower <- quantile(df.subset$velocity_x, 0.15, na.rm = T)[[1]]
data <- df %>%
mutate(velocity_x2 = case_when(
velocity_x >= upper ~ upper,
T ~ velocity_x
)) %>%
mutate(velocity_x3 = case_when(
velocity_x2 <= lower ~ lower,
T ~ velocity_x2
))
mean(data$velocity_x3, na.rm = T)
####
df.subset <- subset(df, fishnum <= '15')
upper <- quantile(df.subset$velocity_x, 0.85, na.rm = T)[[1]]
lower <- quantile(df.subset$velocity_x, 0.15, na.rm = T)[[1]]
data <- df %>%
mutate(velocity_x2 = case_when(
velocity_x >= upper ~ upper,
T ~ velocity_x
)) %>%
mutate(velocity_x3 = case_when(
velocity_x2 <= lower ~ lower,
T ~ velocity_x2
))
mean(data$velocity_x3, na.rm = T)
####
df.subset <- subset(df, fishnum <= '16')
upper <- quantile(df.subset$velocity_x, 0.85, na.rm = T)[[1]]
lower <- quantile(df.subset$velocity_x, 0.15, na.rm = T)[[1]]
data <- df %>%
mutate(velocity_x2 = case_when(
velocity_x >= upper ~ upper,
T ~ velocity_x
)) %>%
mutate(velocity_x3 = case_when(
velocity_x2 <= lower ~ lower,
T ~ velocity_x2
))
mean(data$velocity_x3, na.rm = T)
####
df.subset <- subset(df, fishnum <= '26')
upper <- quantile(df.subset$velocity_x, 0.85, na.rm = T)[[1]]
lower <- quantile(df.subset$velocity_x, 0.15, na.rm = T)[[1]]
data <- df %>%
mutate(velocity_x2 = case_when(
velocity_x >= upper ~ upper,
T ~ velocity_x
)) %>%
mutate(velocity_x3 = case_when(
velocity_x2 <= lower ~ lower,
T ~ velocity_x2
))
mean(data$velocity_x3, na.rm = T)
####
df.subset <- subset(df, fishnum <= '2')
upper <- quantile(df.subset$velocity_x, 0.85, na.rm = T)[[1]]
lower <- quantile(df.subset$velocity_x, 0.15, na.rm = T)[[1]]
data <- df %>%
mutate(velocity_x2 = case_when(
velocity_x >= upper ~ upper,
T ~ velocity_x
)) %>%
mutate(velocity_x3 = case_when(
velocity_x2 <= lower ~ lower,
T ~ velocity_x2
))
mean(data$velocity_x3, na.rm = T)
####
df.subset <- subset(df, fishnum <= '4')
upper <- quantile(df.subset$velocity_x, 0.85, na.rm = T)[[1]]
lower <- quantile(df.subset$velocity_x, 0.15, na.rm = T)[[1]]
data <- df %>%
mutate(velocity_x2 = case_when(
velocity_x >= upper ~ upper,
T ~ velocity_x
)) %>%
mutate(velocity_x3 = case_when(
velocity_x2 <= lower ~ lower,
T ~ velocity_x2
))
mean(data$velocity_x3, na.rm = T)
####
df.subset <- subset(df, fishnum <= '1')
upper <- quantile(df.subset$velocity_x, 0.85, na.rm = T)[[1]]
lower <- quantile(df.subset$velocity_x, 0.15, na.rm = T)[[1]]
data <- df %>%
mutate(velocity_x2 = case_when(
velocity_x >= upper ~ upper,
T ~ velocity_x
)) %>%
mutate(velocity_x3 = case_when(
velocity_x2 <= lower ~ lower,
T ~ velocity_x2
))
mean(data$velocity_x3, na.rm = T)
####
df.subset <- subset(df, fishnum <= '9')
upper <- quantile(df.subset$velocity_x, 0.85, na.rm = T)[[1]]
lower <- quantile(df.subset$velocity_x, 0.15, na.rm = T)[[1]]
data <- df %>%
mutate(velocity_x2 = case_when(
velocity_x >= upper ~ upper,
T ~ velocity_x
)) %>%
mutate(velocity_x3 = case_when(
velocity_x2 <= lower ~ lower,
T ~ velocity_x2
))
mean(data$velocity_x3, na.rm = T)
####
df.subset <- subset(df, fishnum <= '19')
upper <- quantile(df.subset$velocity_x, 0.85, na.rm = T)[[1]]
lower <- quantile(df.subset$velocity_x, 0.15, na.rm = T)[[1]]
data <- df %>%
mutate(velocity_x2 = case_when(
velocity_x >= upper ~ upper,
T ~ velocity_x
)) %>%
mutate(velocity_x3 = case_when(
velocity_x2 <= lower ~ lower,
T ~ velocity_x2
))
mean(data$velocity_x3, na.rm = T)
df.subset <- subset(df, fishnum <= '20')
upper <- quantile(df.subset$velocity_x, 0.85, na.rm = T)[[1]]
lower <- quantile(df.subset$velocity_x, 0.15, na.rm = T)[[1]]
data <- df %>%
mutate(velocity_x2 = case_when(
velocity_x >= upper ~ upper,
T ~ velocity_x
)) %>%
mutate(velocity_x3 = case_when(
velocity_x2 <= lower ~ lower,
T ~ velocity_x2
))
mean(data$velocity_x3, na.rm = T)
